package com.itheima.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

//@WebFilter(urlPatterns = "/*")
@WebFilter(urlPatterns = "/login")
public class DemoFilter implements Filter {

    // 初始化方法，只调用一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init 初始化方法. . .");
    }

    // 拦截到请求之后调用，调用多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("拦截请求. . .");

        System.out.println("放行之前的逻辑. . .");
        // 放行请求
        filterChain.doFilter(servletRequest , servletResponse);
        System.out.println("放行之后的逻辑. . .");
    }

    // 销毁方法，只调用一次
    @Override
    public void destroy() {
        System.out.println("destroy 销毁方法. . .");
    }
}
